package com;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public class SCM_MakeJavaRepository {
	static String[] SRC_DIR = new String[] {
			"C:/develop/WALI/workspace/WALI/java/",
			"C:/develop/WALI/workspace/WALI/WEB/" };
	
	static String REP_ROOT = null;
	static String SRC_ROOT = null;
	static String SRC_TYPE = null;
	static String ANT_DIR = null;
	static String ANT_BATCH_DIR = null;
	public static void main(String[] args) {
		
		try {

			BufferedReader in = new BufferedReader(new FileReader("C:/repository/"+"mapJava.txt"));
			BufferedWriter out = new BufferedWriter(new FileWriter("C:/repository/"+"makeJava.cmd"));
			String str = null;
			SRC_TYPE = SRC_DIR[0];
			while ((str = in.readLine()) != null) {
				String[] val = str.split("	");
				
				if(val.length<4){
					REP_ROOT = val[2];
				}else{
					REP_ROOT = val[2]+val[3];
					ANT_DIR = "ant/"+val[3].toUpperCase();
					ANT_BATCH_DIR = "ant_batch/"+val[3].toUpperCase();
				}				
				
				if(val[1].trim().length()==0){
					val[0] = val[0].replace("/", "");
					SRC_ROOT = "";
				}else{
					SRC_ROOT = "/"+val[1];
				}
				
				if(val[2].contains("java_")){
					SRC_TYPE = SRC_DIR[0];
				}else{
					SRC_TYPE = SRC_DIR[1];
				}				
				
				
				out.write(new String("rmdir "+"C:/repository/"+REP_ROOT                                      ).replace("/", "\\")+" /S/Q"+"\n");
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+SRC_ROOT                             ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+val[1]+" "+"C:/repository/"+REP_ROOT+SRC_ROOT).replace("/", "\\")+" /EHKQ"+"\n");
				
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+"/"+ANT_DIR                       ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+ANT_DIR+" "+"C:/repository/"+REP_ROOT+"/"+ANT_DIR).replace("/", "\\")+" /EHKQ"+"\n");
				
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+"/"+"ant/template"                       ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+"ant/template"+" "+"C:/repository/"+REP_ROOT+"/"+"ant/template").replace("/", "\\")+" /EHKQ"+"\n");
				
				out.write(new String("xcopy "+SRC_TYPE+val[0]+"ant/*.properties"+" "+"C:/repository/"+REP_ROOT+"/"+"ant/").replace("/", "\\")+" /HKQ"+"\n");
				
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+"/"+ANT_BATCH_DIR                      ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+ANT_BATCH_DIR+" "+"C:/repository/"+REP_ROOT+"/"+ANT_BATCH_DIR).replace("/", "\\")+" /EHKQ"+"\n");
				
				out.write(new String("mkdir "+"C:/repository/"+REP_ROOT+"/"+"ant_batch/template"                       ).replace("/", "\\")+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+"ant_batch/template"+" "+"C:/repository/"+REP_ROOT+"/"+"ant_batch/template").replace("/", "\\")+" /EHKQ"+"\n");
				
				out.write(new String("xcopy "+SRC_TYPE+val[0]+"ant_batch/*.properties"+" "+"C:/repository/"+REP_ROOT+"/"+"ant_batch/").replace("/", "\\")+" /HKQ"+"\n");
				out.write(new String("xcopy "+SRC_TYPE+val[0]+"*.properties"+" "+"C:/repository/"+REP_ROOT+"/"+"ant_batch/").replace("/", "\\")+" /HKQ"+"\n");
				
				out.write(new String("copy "+SRC_TYPE+val[0]+".classpath"+" "+"C:/repository/"+REP_ROOT+"/").replace("/", "\\")+" /Y"+"\n");
				out.write(new String("copy "+SRC_TYPE+val[0]+".compatibility"+" "+"C:/repository/"+REP_ROOT+"/").replace("/", "\\")+" /Y"+"\n");
				out.write(new String("copy "+SRC_TYPE+val[0]+".project"+" "+"C:/repository/"+REP_ROOT+"/").replace("/", "\\")+" /Y"+"\n");
				
				
				out.write(new String("dir "+"C:/repository/"+REP_ROOT+SRC_ROOT                               ).replace("/", "\\")+"\n");
				out.write(new String("dir "+"C:/repository/"+REP_ROOT+"/"+"ant"                                ).replace("/", "\\")+"\n");
				out.write(new String("dir "+"C:/repository/"+REP_ROOT+"/"+"ant_batch"                               ).replace("/", "\\")+"\n");
				
				//out.write(new String("dir "+SRC_TYPE+val[0]+"ant  > c:\\Repository\\o_"+val[0].replace("/", "")+".txt"                                ).replace("/", "\\"));
				//out.write(new String("dir "+SRC_TYPE+val[0]+"ant_batch > c:\\Repository\\b_"+val[0].replace("/", "")+".txt"                               ).replace("/", "\\"));
				
				
				out.write("\n");
			}
			out.write(new String("xcopy "+SRC_TYPE+"eGIS_Library "+"C:/repository/"+REP_ROOT+"/java_library").replace("/", "\\")+" /EHKQYI"+"\n");
			out.write("\n");
			out.write("jar -cvfM java.jar java_*"+"\n");
			
			out.write("pause");
			out.flush();
			in.close();
			out.close();

		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
